<?php
namespace Admin\Controller;
use Think\Controller;
class ExcelController extends CommonController {
	public function index(){
		//计算出前N天的提问量还有对应的days
		$sql = "select count(id) cn,FROM_UNIXTIME(create_time,'%m-%d') days from question GROUP BY days order by days limit 7";
    	$res = M()->query($sql);
    	

    	$arr = [
    		0 => [
    			'date' => '2016-06-06',
    		],
    		1=>[
    			'date' => '2016-06-09',
    		],
    	];
    	while ( $value = array_shift($arr)) {
    		$result[] = $value;

    	}
    	var_dump($result);


		$this->display();
	}

	public function ajaxData(){
		$sql = "select count(id) cn,FROM_UNIXTIME(create_time,'%m-%d') days from question GROUP BY days ORDER BY days desc limit 7";
    	$res = M()->query($sql);

    	$tmp = array();

    	foreach ($res as $key => $value) {
    		$tmp[]=$value['cn'];
    	}

    	$sum = array_sum($tmp);

    	$res[]=array(
    		'cn'=>$sum,
    		'days'=>'总量',
    		);
    	
    	$res = array_reverse($res);

    	echo json_encode($res);
	}
}